package com.shujia.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo17Reduce {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setMaster("local")
      .setAppName("Demo14Agg")


    val sc = new SparkContext(conf)
    val listRDD: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4, 5, 6, 7, 8, 9))

    /**
      * sum 求和，action算子 只能用于int或者double,long类型的求和
      *
      */
    val sum: Double = listRDD.sum()
    println(sum)

    /**
      * reduce: 全局聚合, action算子
      * reduceBykYe 通过key进行聚合
      */
    val reduce: Int = listRDD.reduce((x, y) => x + y)
    println(reduce)

  }

}
